faker: Tab completion in interactive shell not working since Python version 3.8
Tab autocomplete in python interactive shell unavailable when using Python versions 3.9, 3.10 or 3.11.
Python documents this feature: https://docs.python.org/3.11/tutorial/interactive.html#tab-completion-and-history-editing. (Docs here are the same in all versions of Python)
Setup
- Faker version: 17.3.0
- OS: Debian GNU/Linux 11 (bullseye)
OS versions
PS C:\Users\User> docker run -it --rm python:3.8 cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
PS C:\Users\User> docker run -it --rm python:3.9 cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
PS C:\Users\User> docker run -it --rm python:3.10 cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
PS C:\Users\User> docker run -it --rm python:3.11 cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
What used to work
# pip install faker=="17.3.0"
# python
>>> import faker
>>> fake = faker.Faker()
>>> fake.
Type [TAB] once or twice and you see this:
Display all 280 possibilities? (y or n)
fake.aba( fake.generator_attrs fake.pyfloat(
fake.add_provider( fake.get_arguments( fake.pyint(
fake.address( fake.get_formatter( fake.pyiterable(
... I've removed a whole bunch for brevity's sake.
fake.free_email( fake.psv( fake.zipcode_in_state(
fake.free_email_domain( fake.pybool( fake.zipcode_plus4(
fake.future_date( fake.pydecimal(
fake.future_datetime( fake.pydict(
>>> fake.
What’s broken
In Python 3.9, 3.10, and 3.11:
# pip install faker=="17.3.0"
# python
>>> import faker
>>> fake = faker.Faker()
>>> fake.
Type [TAB] once or twice and nothing happens.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 10
- Comments: 50 (23 by maintainers)
I’m just commenting to say that I’d greatly appreciate this feature as well. I’d imagine it would be trivial to add a mypy stub or similar to declare all of the many provider’s attributes as members of the base Faker class. I’m trying to write the stub file myself, I’ll try to remember to report back if it works.
This is a night and day difference.
Environment
77d25e7Instructions
You should now see this with
git status:If the
faker/proxy.pyistub is there, you will be able to see typings if you open any file, e.g.tests/test_proxy.pyBefore (via here)
With faker-stubs @
77d25e7Locale / faker constructor
re: locales
If the constructor itself allowed
locale, we’d get around this particular one. Though we wouldn’t have locale-specific ones.I see the same problem on Python 3.9 in PyCharm. I wonder if this is just due to the high level of dynamism in Faker? I.e. attributes are added in via
__getattribute__so static type checkers cannot resolve them?But makes the library a pain to use as not discoverable via IDE.
Can anyone else replicate this?
I showed you how to run this in docker, so hopefully it should be easy enough to duplicate. (The issue can be demonstrated outside of docker btw)
@tony I assume that pinging @fcurella here would make much sense, as he is the active maintainer at the moment.
@tony well I seem to have made something helpful but objectively not very Pythonic. https://github.com/KaylaHood/faker-stubs
I wrote a little script that makes heavy use of the standard lib
inspectpackage to generate a stub for Faker’s proxy.py file so that auto-completion forfaker.Faker()instances will contain every provider method for every locale. It works for my use case (Windows 10, Python 3.9), but I didn’t spend time testing it for other platforms.You have to run the stub generator every time you install/upgrade Faker; I can see it getting tedious very quickly.
If you use poetry or some other python package management tool you could write a post-build script that automates the download and execution of my stub generation script.
NOTE: the automated stub generation solution I just described should NEVER be used for a production or client-facing application. You don’t know me! I could change my stub generation script to be a data miner! (I wouldn’t, but y’know what I mean) If you would like to incorporate it into your product, then consider forking my repo to your own github/artifactory/server/etc and then use your cloned version of my script in your product’s build pipeline.
Hopefully you find it useful!
Summary
IntelliCode and Kite-AI Auto-completion not working in VSCode.
Screenshot (Click to expand)
Python Docs unavailable both in VSCode IntelliCode and Kite Copilot.
Screenshots (Click to expand)
Auto-completion available as it should in IPython, however …
Screenshot
Environments
winget.exeSteps to reproduce
Setup Python 3.9 or later version
Install the latest version of
FakerInstalled the latest version of Microsoft Visual Studio Code
Open an empty folder as a VSCode workspace, and create an empty
*.pyfileType in the following snippet
Invoke auto-completion (mostly
Ctrl + Space) after the dot, check if all available methods are listed.Expected Behavior
Faker’s class, instance or method.Actual Behavior
As I mentioned before in “Summary” section.
Notes
Kite Engine and IntelliCode for VSCode are enabled and ready. It’s not Kite or VSCode’s fault.
Screenshot (Click to expand)
Of course! I’d love that!
On Tue, Oct 17, 2023 at 2:16 PM Viicos @.***> wrote:
Me too! It is a big caveat for me, that there is no any type hints for possible data. Mimesis offers that, so if there is comparison, lack of annotations is much bigger deal
@KaylaHood Follow up to https://github.com/joke2k/faker/issues/1604#issuecomment-1312496383 + https://github.com/joke2k/faker/issues/1604#issuecomment-1312799159
Environment
5c7ffc2…New docstring completions + locale kwarg
This looks good.
Got it and this looks good (screenshot 1)
Roger that, and this looks good (screenshot 1)
Provider functions v. member names
Good catch here as well
Before, with faker-stubs @
77d25e7With faker-stubs @
d555b36:With faker-stubs @
5161681:With faker-stubs @
5c7ffc2:Side note, re:
**config: Any**config: Anyon the faker side permits anything, https://github.com/joke2k/faker/blob/bc56a8f37f4a1aef3b2fc6c4efb69cfcf28606e0/faker/proxy.py#L34I’ve never used any
**configkwargs, so I’m not sure what this is used for. If it’s something deterministic, there’s new PEPs and backported support available:typing_extensionssince 4.1.0 (thoughTypedDictmust be imported viatyping_extensions@KaylaHood I try your repo and it works great on my device! Thank you!
Environments
Screenshots
We could integrate @KaylaHood 's script in our CI build and run it before every release, but that would still not cover community providers that users have installed on their own.
On one hand, that’d be better than nothing. On the other, it may set the wrong expectation on users.
@KaylaHood You are correct in factories and metaclasses masking completions due to being reliant on runtime.
If you accomplish anything it’d be nice to see where it goes. But it may be too runtime-heavy to get completion and typings for.
Everybody wants completions for faker
edit: I don’t believe anybody specifically doesn’t want it 😃
In Ubuntu 20.04 I can’t replicate it with Python3.9 installed using APT from default repositories, but Python3.10 installed from deadsnakes PPA has this problem.