Giter VIP home page Giter VIP logo

Comments (10)

ashwin153 avatar ashwin153 commented on August 21, 2024 1

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.

mkorpela avatar mkorpela commented on August 21, 2024

Thanks @cboots extremely interesting edge case and good point about getting the error message improved!

from overrides.

mkorpela avatar mkorpela commented on August 21, 2024

So named and positional arguments should be checked separately.

from overrides.

ashwin153 avatar ashwin153 commented on August 21, 2024

@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.

brentyi avatar brentyi commented on August 21, 2024

Mentioned in another issue, but there's also some relevant discussion on enforcement considerations in python/mypy#6709.

from overrides.

mkorpela avatar mkorpela commented on August 21, 2024

I think named and positional arguments should be checked separately.

from overrides.

mkorpela avatar mkorpela commented on August 21, 2024

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.

mkorpela avatar mkorpela commented on August 21, 2024

Added as a test to master ac8012f

from overrides.

mkorpela avatar mkorpela commented on August 21, 2024

Fixed after dc3b449

from overrides.

mkorpela avatar mkorpela commented on August 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.