Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stubs for WebOb #9874

Merged
merged 21 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
46ebabc
Add stubs for WebOb
Daverball Mar 13, 2023
5c9868a
Fixes up some issues reported by pyright and pytype
Daverball Mar 13, 2023
a0dd49d
Merge remote-tracking branch 'upstream/main' into webob
Daverball Mar 13, 2023
f9470bc
Fixes a couple of additional issues
Daverball Mar 13, 2023
ca38af6
Makes stubtest happy
Daverball Mar 13, 2023
10c53c7
Fixes `webob.request.NoDefault` annotation
Daverball Mar 13, 2023
45eaa9d
Adds comments to the allowlist
Daverball Mar 13, 2023
f53e00c
Adds some missing type annotations and fixes issues uncovered in testing
Daverball Mar 18, 2023
0895b80
Gets rid of string type complexity that was removed upstream
Daverball Mar 20, 2023
b0770d1
Finishes up exc module. Missed a couple of easy `Incomplete`s.
Daverball Mar 21, 2023
5770e4d
Switches to typeshed's wsgi types
Daverball Mar 23, 2023
c56a005
Consistently uses `WSGIEnvironment` wherever appropriate
Daverball Mar 23, 2023
69a4c14
Runs stubdefaulter
Daverball Mar 27, 2023
2e2d682
Fixes broken overload for `lookup` method in `Webob.acceptparse`
Daverball Mar 27, 2023
944afe7
Merge remote-tracking branch 'upstream/main' into webob
Daverball Mar 30, 2023
17c51c3
Fixes up acceptparse module. Adds a couple of overlooked annotations.
Daverball Mar 30, 2023
71b4609
Merge branch 'main' into webob
AlexWaygood Apr 24, 2023
7f0f743
Apply suggestions from code review
Daverball Jun 8, 2023
b5ca284
Fixes missing `@wsgify` in `__call__` methods in `webob.static`
Daverball Jun 13, 2023
6c1f699
Gets rid of `NoReturn` in `webob.multidict`.
Daverball Jun 15, 2023
de30e65
Gets rid of the remaining two uses of `NoReturn`
Daverball Jun 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"stubs/ttkthemes",
"stubs/urllib3",
"stubs/vobject",
"stubs/WebOb"
],
"typeCheckingMode": "strict",
// TODO: Complete incomplete stubs
Expand Down
153 changes: 153 additions & 0 deletions stubs/WebOb/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Error: is not present in stub
# =============================
# These are plain strings, regex strings or compiled regex patterns
# which are used internally for parsing, so they should not be public API
webob.acceptparse.Accept.accept_compiled_re
webob.acceptparse.Accept.accept_ext_compiled_re
webob.acceptparse.Accept.accept_ext_re
webob.acceptparse.Accept.accept_params_re
webob.acceptparse.Accept.media_range_n_accept_params_compiled_re
webob.acceptparse.Accept.media_range_n_accept_params_re
webob.acceptparse.Accept.media_range_re
webob.acceptparse.Accept.media_type_compiled_re
webob.acceptparse.Accept.media_type_re
webob.acceptparse.Accept.obs_text_re
webob.acceptparse.Accept.parameter_re
webob.acceptparse.Accept.parameters_compiled_re
webob.acceptparse.Accept.qdtext_re
webob.acceptparse.Accept.quoted_pair_re
webob.acceptparse.Accept.quoted_string_re
webob.acceptparse.Accept.subtype_re
webob.acceptparse.Accept.type_re
webob.acceptparse.Accept.vchar_re
webob.acceptparse.AcceptCharset.accept_charset_compiled_re
webob.acceptparse.AcceptCharset.charset_n_weight_compiled_re
webob.acceptparse.AcceptCharset.charset_n_weight_re
webob.acceptparse.AcceptCharset.charset_re
webob.acceptparse.AcceptEncoding.accept_encoding_compiled_re
webob.acceptparse.AcceptEncoding.codings_n_weight_compiled_re
webob.acceptparse.AcceptEncoding.codings_n_weight_re
webob.acceptparse.AcceptEncoding.codings_re
webob.acceptparse.AcceptLanguage.accept_language_compiled_re
webob.acceptparse.AcceptLanguage.lang_range_n_weight_compiled_re
webob.acceptparse.AcceptLanguage.lang_range_n_weight_re
webob.acceptparse.AcceptLanguage.lang_range_re
webob.acceptparse.OWS_re
webob.acceptparse.qvalue_re
webob.acceptparse.tchar_re
webob.acceptparse.token_compiled_re
webob.acceptparse.token_re
webob.acceptparse.weight_re
webob.cachecontrol.need_quote_re
webob.cachecontrol.token_re
webob.client.SendRequest.MULTILINE_RE
webob.descriptors.CHARSET_RE
webob.descriptors.SCHEME_RE

webob.acceptparse.MIMEAccept # Deprecated API

# PY2 compat stuff that has already been removed upstream
webob.compat
webob.multidict.MultiDict.iteritems
webob.multidict.MultiDict.iterkeys
webob.multidict.MultiDict.itervalues
webob.multidict.NestedMultiDict.iteritems
webob.multidict.NestedMultiDict.iterkeys
webob.multidict.NestedMultiDict.itervalues
webob.multidict.NoVars.iterkeys

# NoVars implements the MultiDict interface for better runtime errors
# but it is annoying for type checking, so the methods that are not
# valid to call on NoVars have been removed. In the future we would
# like to switch to a @type_error() decorator
webob.multidict.NoVars.__getitem__
webob.multidict.NoVars.__setitem__
webob.multidict.NoVars.__delitem__
webob.multidict.NoVars.add
webob.multidict.NoVars.setdefault
webob.multidict.NoVars.update
webob.multidict.NoVars.clear
webob.multidict.NoVars.pop
webob.multidict.NoVars.popitem
webob.multidict.NoVars.getone

# ResponseBodyFile cannot be closed and emits an Exception, so we're better
# off pretending the method doesn't exist
webob.response.ResponseBodyFile.close

# Error: is inconsistent
# ======================
# set_cookie has a deprecated argument `expires` which has been removed upstream
webob.Response.set_cookie
webob.response.Response.set_cookie

# These methods have been moved from their subclasses to the shared hidden superclass
# since the method signatures are the same, so this saves some copy pasta and should
# not affect type checking or runtime behavior in any way
webob.acceptparse._AcceptCharsetInvalidOrNoHeader.__add__
webob.acceptparse._AcceptCharsetInvalidOrNoHeader.__radd__
webob.acceptparse._AcceptCharsetInvalidOrNoHeader.copy
webob.acceptparse._AcceptCharsetInvalidOrNoHeader.parsed
webob.acceptparse._AcceptEncodingInvalidOrNoHeader.__add__
webob.acceptparse._AcceptEncodingInvalidOrNoHeader.__radd__
webob.acceptparse._AcceptEncodingInvalidOrNoHeader.copy
webob.acceptparse._AcceptEncodingInvalidOrNoHeader.parsed
webob.acceptparse._AcceptInvalidOrNoHeader.__add__
webob.acceptparse._AcceptInvalidOrNoHeader.__radd__
webob.acceptparse._AcceptInvalidOrNoHeader.copy
webob.acceptparse._AcceptInvalidOrNoHeader.parsed
webob.acceptparse._AcceptLanguageInvalidOrNoHeader.__add__
webob.acceptparse._AcceptLanguageInvalidOrNoHeader.__radd__
webob.acceptparse._AcceptLanguageInvalidOrNoHeader.copy
webob.acceptparse._AcceptLanguageInvalidOrNoHeader.lookup
webob.acceptparse._AcceptLanguageInvalidOrNoHeader.parsed

# These are here due to the slightly more strict nature of the type annotation
# of these descriptors for type checking, it does not really have any runtime
# consequences since `_IntValueProperty` derives from `value_property` and
# only makes `__set__` slightly more strict.
webob.cachecontrol.CacheControl.max_age
webob.cachecontrol.CacheControl.max_stale
webob.cachecontrol.CacheControl.min_fresh
webob.cachecontrol.CacheControl.s_max_age
webob.cachecontrol.CacheControl.s_maxage
webob.cachecontrol.CacheControl.stale_if_error
webob.cachecontrol.CacheControl.stale_while_revalidate
webob.cachecontrol.CacheControl.update_dict
webob.cachecontrol.UpdateDict.setdefault

# These need to be ignored due to how WebOb decided to let people know
# that certain methods on `NestedMultiDict` should not be called since
# they are immutable, compared to a MultiDict, but still can be used
# interchangeably in some parts of the API. So they re-use generic functions
# that accept any parameters and assign them to methods which should still
# satisfy the same interface. The type annotations enforce the correct
# input arguments instead of the generic ones.
webob.multidict.NestedMultiDict.popitem
webob.multidict.NestedMultiDict.clear

# The `DEFAULT` parameter on these dunder methods don't really make sense as
# part of the public API, so they have been removed from the stubs
webob.request.AdhocAttrMixin.__delattr__
webob.request.AdhocAttrMixin.__getattr__
webob.request.AdhocAttrMixin.__setattr__

# BaseRequest has a bunch of named parameters that have been deprecated and
# removed upstream, since there's a `**kwargs` anyways, it doesn't really
# make sense to annotate them and pretend they're part of the API.
webob.request.BaseRequest.__init__

# Error: is not present at runtime
# =============================
# This attribute is there to help mypy type narrow NoVars based on its static
# falsyness, so it's to make it possible to narrow the type union in request.POST
# without importing MultiDict or NoVars
webob.multidict.NoVars.__bool__

# This attribute is set on the instance instead of the class in the `__init__`
# so the type annotation is technically wrong, however I am unsure about
# whether the ResponseBodyFile would satisfy some of the IO Protocols if
# `write` was defined as a Callable instance attribute. It's hard to come up
# with a use-case where the distinction matters, besides inherting from
# the class and overwriting the __init__ and forgetting to populate `write`.
webob.response.ResponseBodyFile.write
1 change: 1 addition & 0 deletions stubs/WebOb/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.8.*"
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions stubs/WebOb/webob/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from webob.datetime_utils import (
UTC as UTC,
day as day,
hour as hour,
minute as minute,
month as month,
second as second,
week as week,
year as year,
)
from webob.request import LegacyRequest as LegacyRequest, Request as Request
from webob.response import Response as Response
from webob.util import html_escape as html_escape
Loading