Giter Site home page Giter Site logo

Comments (6)

jasonkuhrt avatar jasonkuhrt commented on May 5, 2024 1

@dark ahhhhh sorry my eyes glazed over that, of course. Thanks.

from pyre-check.

dark avatar dark commented on May 5, 2024

Hi @jasonkuhrt , Pyre is warning you that you gen does not return any value. You need to add a return statement for that to work. That is also the case for the basic function.
basic does not throw any visible error here because string is not a type (for the record, this is the stub for the string module: https://github.com/python/typeshed/blob/master/stdlib/3/string.pyi)
You can see more low-level errors like this with pyre --debug check:

foo.py:68:4 Incompatible return type [7]: Expected str but got None.
foo.py:70:0 Undefined type [11]: Type string is not defined.

After correcting the file, no errors are generated for me:

import random
import string

def gen(allowed_chars: str, length: int) -> str:
    return ''.join([random.choice(allowed_chars) for _ in range(1, length)])

def basic(length: int) -> str:
    return gen(string.ascii_letters + string.digits, length)

Feel free to reopen this issue if you have further related questions.

from pyre-check.

jasonkuhrt avatar jasonkuhrt commented on May 5, 2024

basic does not throw any visible error here because string is not a type

I don't understand this. basic returns None but its type says that it will return str. What am I doing wrong exactly?

from pyre-check.

dark avatar dark commented on May 5, 2024

Let me rephrase - the error about a missing return in basic is being masked by the use of an unknown type string. In cases like this we are trying to be conservative and not display the error because the type might be legitimate and simply not being defined in a stub.

from pyre-check.

jasonkuhrt avatar jasonkuhrt commented on May 5, 2024

@dark I see, thanks. Could I fix this at the project level via local defs? The issue is that I'm using e.g. ascii_letters which has def:

ascii_letters = ...  # type: str

from pyre-check.

dark avatar dark commented on May 5, 2024

@jasonkuhrt Using the imported string module is totally fine -- and it works!
The problem was with the following incorrect type definition for the parameter of gen: allowed_chars: string. String is a module, not a type, so the correct definition would be allowed_chars: str. Please see the fixed code I posted in my first comment for all things I needed to change.

from pyre-check.

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.