Giter Club home page Giter Club logo

Comments (4)

JelleZijlstra avatar JelleZijlstra commented on May 11, 2024

Thanks for the report! The issue here is actually that pyanalyze doesn't deal with list.__getitem__ at all. This is basically an instance of #64, a place where it unexpectedly isn't able to infer something.

Subscripts get handled in https://github.com/quora/pyanalyze/blob/master/pyanalyze/name_check_visitor.py#L3327. It has some special cases for SequenceIncompleteValue, so you'll see int subscripts work for some cases where pyanalyze has a precise type, but for general lists it will just fall back to the return type of list.__getitem__. Because that method is overloaded in typeshed (https://github.com/python/typeshed/blob/master/stdlib/builtins.pyi#L776), pyanalyze doesn't know what to do with it and just returns Any.

This isn't exactly going to be trivial to fix. I see two ways out:

  • Add support for overloads (#182). That's going to be a pretty big project. I'll probably take it on after I get protocols working, but it may be a while.
  • Add an implementation function for list.__getitem__ in implementations.py, similar to the existing one for dict.__getitem__. Doing this will allow us to get rid of some more special casing in name_check_visitor.py. We'd also want a very similar impl for tuple.__getitem__.

The second option shouldn't be too hard if you're interested in taking it on. I'd recommend looking at the existing implementation functions for dict.__getitem__ and other list methods as examples.

(Also, sorry for not responding earlier; I was out of town.)

from pyanalyze.

JelleZijlstra avatar JelleZijlstra commented on May 11, 2024

#241 should fix this.

from pyanalyze.

erezsh avatar erezsh commented on May 11, 2024

Nice!

I'm glad to see there's so much recent activity. Mind if I ask what's your new goal?

from pyanalyze.

JelleZijlstra avatar JelleZijlstra commented on May 11, 2024

An internal use case came up that required some pyanalyze changes. While implementing that I noticed a bunch of other bugs that affected us, so I decided to fix them. The one from #242 is especially nasty; I still have a lot of things I need to fix internally before I can merge that one. I'm thinking of cutting a release once I get all these resolved.

from pyanalyze.

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.