Comments (10)
To summarize the discussion, the mypy contributors agree that this is an invalid override but are worried about breaking too many people if they start checking it now. It will; however, check this if --strict
. I think that overrides has the opportunity to be strict by default, because it has much fewer users than mypy. What do you guys think?
from overrides.
Thanks @cboots extremely interesting edge case and good point about getting the error message improved!
from overrides.
So named and positional arguments should be checked separately.
from overrides.
@cboots I think the problem is that x
can be passed as a positional or keyword argument in A
, but only as a keyword argument in B
. In other words, a.methoda(1)
is a valid call on A
but b.methoda(1)
does something completely different on B
. Changing the signature of A.methodA
to def methoda(self, *, x=0)
resolves this ambiguity. The error message can definitely be improved though.
class A(EnforceOverrides):
def methoda(self, *, x=0):
pass
class B(A):
@overrides
def methoda(self, y=1, **kwargs):
pass
from overrides.
Mentioned in another issue, but there's also some relevant discussion on enforcement considerations in python/mypy#6709.
from overrides.
I think named and positional arguments should be checked separately.
from overrides.
From original example
# positional checking
A().methoda()
B().methoda()
# -> ok
A().methoda(1)
B().methoda(1)
# -> ok -> positionals match
# named checking
A().methoda(x=3)
B().methoda(x=3)
# -> ok -> named match
# -> B.methoda signature overrides A.methoda signature
from overrides.
Added as a test to master ac8012f
from overrides.
Fixed after dc3b449
from overrides.
@cboots we now have 5.0.0b0 out. This should fix the issues that you have reported.
Could you test this pre-release version to ensure that everything works?
from overrides.
Related Issues (20)
- Failed when overriding a decorated function HOT 4
- Feature request: allow renaming unused variables HOT 2
- Inner classes are recognized as methods by EnforceOverrides HOT 4
- Sic .. so maybe override also? HOT 1
- Does `override` need to be overloaded explicitly? HOT 3
- Do some caching of base lookup HOT 1
- `overrides` is incompatible with `nuitka` HOT 1
- False positive when checking parameter with Callable HOT 25
- Error when using pipe for union types HOT 3
- tests/test_enforce__py38.py::EnforceTests::test_enforcing_when_incompatible fails with Python 3.12 HOT 6
- Test failures with pypy3.10 7.3.13 HOT 10
- Docs request: IDE linting guidance HOT 1
- Regression in version 7.6.0 when base class name has more than one level of nesting HOT 3
- `AttributeError` from `overrides` in conjunction with `typing_extensions.Literal` in subclass HOT 2
- Move away from `distutils`: please migrate to `pyproject.toml`
- @overrides cause maximum recursion depth exceeded when input argument has Literal HOT 10
- Overrides breakes SOLID Liskov rule? HOT 1
- TypedDict is treated as different class as Dict[str, Any] HOT 5
- `threading.Lock` is not recognized as a `ContextManager` HOT 1
- TypeError: DictionaryField.batch_tensors: `tensor_list` is not present. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overrides.