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
Enable mypy-zope plugin #471
Conversation
Getting an INTERNAL ERROR after just enabling it: GLOB sdist-make: /home/runner/work/klein/klein/setup.py
mypy create: /home/runner/work/klein/klein/.tox/mypy
mypy installdeps: mypy==0.812, mypy-zope==0.2.11, Twisted==20.3.0, attrs==20.3.0, Automat==20.2.0, characteristic==14.3.0, constantly==15.1.0, hyperlink==21.0.0, incremental==17.5.0, PyHamcrest==2.0.2, six==1.15.0, Tubes==0.2.0, Werkzeug==1.0.1, zope.interface==5.2.0
mypy inst: /home/runner/work/klein/klein/.tox/.tmp/package/1/klein-20.6.0.zip
mypy installed: attrs==20.3.0,Automat==20.2.0,characteristic==14.3.0,constantly==15.1.0,hyperlink==21.0.0,idna==3.1,incremental==17.5.0,klein @ file:///home/runner/work/klein/klein/.tox/.tmp/package/1/klein-20.6.0.zip,mypy==0.812,mypy-extensions==0.4.3,mypy-zope==0.2.11,PyHamcrest==2.0.2,six==1.15.0,Tubes==0.2.0,Twisted==20.3.0,typed-ast==1.4.2,typing-extensions==3.7.4.3,Werkzeug==1.0.1,zope.event==4.5.0,zope.interface==5.2.0,zope.schema==6.1.0
mypy run-test-pre: PYTHONHASHSEED='688791434'
mypy run-test: commands[0] | mypy --cache-dir=/home/runner/work/klein/klein/.tox/mypy_cache release.py setup.py src
src/klein/test/test_trial.py:33: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues
version: 0.812
src/klein/test/test_trial.py:33: : note: please use --show-traceback to print a traceback when reporting a bug
ERROR: InvocationError for command /home/runner/work/klein/klein/.tox/mypy/bin/mypy --cache-dir=/home/runner/work/klein/klein/.tox/mypy_cache release.py setup.py src (exited with code 2)
___________________________________ summary ____________________________________
ERROR: mypy: commands failed
Error: Process completed with exit code 1. Filed as Shoobx/mypy-zope#37 |
…y` without `mypy-zope`.
@@ -123,7 +123,7 @@ def procureSession( | |||
] | |||
# Does it seem like this check is expensive? It sure is! Don't want | |||
# to do it? Turn on your dang HTTPS! | |||
yield self._store.sentInsecurely(allPossibleSentTokens) | |||
self._store.sentInsecurely(allPossibleSentTokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sentInsecurely()
returns None
and is not async, so mypy complains about this unnecessary yield
.
src/klein/test/test_trial.py
Outdated
class IFrobbable(Interface): | ||
""" | ||
Tests for L{TestCase}. | ||
Frobbable object. | ||
""" | ||
|
||
class IFrobbable(Interface): | ||
def frob() -> None: | ||
""" | ||
Frobbable object. | ||
Frob the object. | ||
""" | ||
|
||
@ifmethod | ||
def frob() -> None: | ||
""" | ||
Frob the object. | ||
""" | ||
|
||
class TestCaseTests(TestCase): | ||
""" | ||
Tests for L{TestCase}. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to module scope to make mypy-zope
happy.
""" | ||
Interface for adding hooks to the phases of a request's lifecycle. | ||
""" | ||
|
||
def addPrepareHook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users of IRequestLifecycle
are expecting this.
src/klein/storage/_memory.py
Outdated
@@ -55,7 +55,7 @@ class _MemoryAuthorizerFunction: | |||
Type shadow for function with the given attribute. | |||
""" | |||
|
|||
__memoryAuthInterface__: IInterface = None | |||
__memoryAuthInterface__: IInterface = None # type: ignore[assignment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't allow this to be set to None
outside of init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is fine.
Another options is to __memoryAuthInterface__ = IUndeclared
or something like that
then in fromAuthorizers
raise an error if IUndeclared is found.
I see that current code is not doing any checks for None - https://github.com/twisted/klein/pull/471/files#diff-02fadd59dbc54e2a28f4f2c604d476196047564bb71c63cea2e8c3f74c56b701R114
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally agree, though I think None is fine in this context and don't see there need to define an IUndeclared
.
I added an assertion above the line were __memoryAuthInterface__
is accessed to make sure it isn't still None
.
@@ -458,6 +458,11 @@ class IProtoForm(Interface): | |||
Marker interface for L{ProtoForm}. | |||
""" | |||
|
|||
def addField(field: Field) -> "FieldInjector": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users of IProtoForm
expect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks so much cleaner now :)
I think the interface updates might break in theory backward compatibility.
I have no idea how to implement bacward compatible interface changes.
I guess the only options is IProtoForm and then IProtoFormV2(IProtoForm)
I have no idea how many klein users are implementing their own forms.
Thanks!
src/klein/storage/_memory.py
Outdated
@@ -55,7 +55,7 @@ class _MemoryAuthorizerFunction: | |||
Type shadow for function with the given attribute. | |||
""" | |||
|
|||
__memoryAuthInterface__: IInterface = None | |||
__memoryAuthInterface__: IInterface = None # type: ignore[assignment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is fine.
Another options is to __memoryAuthInterface__ = IUndeclared
or something like that
then in fromAuthorizers
raise an error if IUndeclared is found.
I see that current code is not doing any checks for None - https://github.com/twisted/klein/pull/471/files#diff-02fadd59dbc54e2a28f4f2c604d476196047564bb71c63cea2e8c3f74c56b701R114
src/klein/storage/_memory.py
Outdated
@@ -55,7 +55,7 @@ class _MemoryAuthorizerFunction: | |||
Type shadow for function with the given attribute. | |||
""" | |||
|
|||
__memoryAuthInterface__: IInterface = None | |||
__memoryAuthInterface__: IInterface = None # type: ignore[assignment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to encourage assigning None
after initialization.
Don't need to accept Any; object will do.
src/klein/test/test_request.py
Outdated
# type note: This returns a FrozenHTTPRequest, which implements | ||
# IHTTPRequest, which is a subclass of IHTTPMessage. | ||
# Seems like a bug in mypy-zope. | ||
return cls.requestFromBytes(data) # type: ignore[return-value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File a bug on mypy-zope and update this comment with a link
src/klein/test/test_response.py
Outdated
# type note: This returns a FrozenHTTPResponse, which implements | ||
# IHTTPResponse, which is a subclass of IHTTPMessage. | ||
# Seems like a bug in mypy-zope. | ||
return cls.responseFromBytes(data) # type: ignore[return-value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File a bug on mypy-zope and update this comment with a link
There are still some mypy errors here, as there are a lot of these "marker interfaces" in play, and I don't understand why we have interfaces with zero defined API in them and then there's this injection magic, etc. I don't use (or really understand) this API at all, so… shrug… it seems like the API I added to @glyph, I think this is your creation, so it would be nice if you had a few cycles to clean up the last bits here… |
I'm (supposedly) taking the day off but filtering this kind of email is a project that is hard to bother with for less than a week's worth of vacation so I guess I might as well reply :). As far as I can tell the interface changes that Adi raised concerns about are fine, because:
I think I can find a couple of cycles next week to address the stuff in the implementation code but most of the stuff in test code is boring enough that I'll |
I agree with this, GVOS applies |
some of them, as you observed, are just wrong, because mypy was previously providing no assistance and However, some of them are to satisfy some mechanical requirements because they require more from the technology than it can currently provide. For example: Discarding some of the jargon here it's like the problem with functions that modify a function signature by adding or removing an expected positional or keyword argument. There's just no way to tell Mypy "oh, it's like whatever function you got, but wiht these modifications", much as you can't say "well it's like a |
All of that could be more clearly described than "marker interface" so maybe I'll give that a shot as well. |
|
Garden Valley Oil Services? |
Gross Violation Of Specifications, from the twisted compat policy |
…ute in IProtoForm.
Codecov Report
@@ Coverage Diff @@
## master #471 +/- ##
==========================================
- Coverage 38.38% 37.74% -0.65%
==========================================
Files 45 44 -1
Lines 3887 3850 -37
Branches 249 249
==========================================
- Hits 1492 1453 -39
- Misses 2392 2394 +2
Partials 3 3
Continue to review full report at Codecov.
|
Enable Mypy-Zope so that we can properly type check the use of Zope Interface classes and remove the various hacks we have in place to make Mypy happy without the plugin.