« first day (4866 days earlier)      last day (310 days later) » 

00:20
yeah, sorry, but we're not going to read your unformatted code that lost all its indentation
00:40
@ThiefMaster can you please guide me how to ensure that the indentation is kept intact while posting questions here?
hit the "fixed font" button in next to the chat field
01:02
@roganjosh I've not tried to write Rust in a while, but when I do I take anything which compiles... so I must be a real terrible person ;)
 
4 hours later…
04:52
Can someone point me to a standard python project setup resembling a template, that also would work with mypy, as well as the standard mypy command that should validate all the types? I am really struggling as even when I have a new project with almost no code and try to do everything in the most standard way possible mypy only understands fully qualified imports. I have been looking through the docs and asking ChatGPT, but it's not helping.
 
3 hours later…
07:48
@Ankit There is a guide listed in the room metadata here (top right of the screen)
You cannot mix regular text and code formatting. If you want to add explanatory text that isn't a code comment then you will need to do it in two messages. However, in future please make use of the sandbox room if you are unsure instead of spamming us with the same broken message
 
1 hour later…
09:12
@still_dreaming_1 What kind of imports are you using that are not fully qualified?
 
6 hours later…
14:47
@MisterMiyagi Importing my own modules, from the same project, actually the same subpackage. I'm getting: Cannot find implementation or library stub for module named "cfg" together with See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports. I have looked up and read those docs and I'm still stuck. I have tried many things, changing the project structure, running mypy from different locations, adding a mypy_path setting under [tool.mypy] in pyproject.toml
That's why I'm asking for an example of something completely standard, I just need to get anything at all working, then I should be able to move forward from there. As far as project structure goes, does having a project_root/src/package directory require more mypy settings for it to work right compared to just project_root/package? I'm new to pything, and generally like to keep my code in a src/, but if that makes things more complicated, I'm willing to ditch it. I've tried both ways though...
The only time I get different errors is if I cd into the submodule directory that has the code and run mypy from there. Then I get an error that is even more strange: `cfg.py: error: Source file found twice under different module names: "pybot.cfg" and "cfg"`.
pybot is the name of my project/package. `cfg` is the name of a module/file (the file is cfg.py). It contains a class named Cfg.
* all the code is in the same package. There is only one directory that has code, so not even dealing with subpackages yet.
The import line generating the first error is:
`from cfg import Cfg`
If I run mypy from the `pybot` directory, the existence of the cfg.py file/module triggers the other error.
I can't reproduce the issue. Can you provide an MVCE?
#!/bin/bash
mkdir -p src/bar src/foo
echo "def test_foo() -> int: return 0" > src/foo/__init__.py
echo "from foo import test_foo; reveal_type(test_foo())" > src/bar/__init__.py
mypy src
src/bar/__init__.py:1: note: Revealed type is "builtins.int"
Success: no issues found in 2 source files
15:04
@Peilonrayz Thanks. I think you just provided what I originally asked for, a template that should work with mypy and the command to run and from where. I will try it and see what happens.
However, you have code inside the _init_.py, is that normal?
No, contrived examples are contrived.
Theoretically, if those files were blank and and that same code was placed in different files in the same directories, it should still work right?
@still_dreaming_1 This looks like your imports are actually broken. If you have a folder structure beginning with package and there's a cfg module/package inside, your imports must look like import package.cfg, from . import cfg, from package import cfg, etc.`
@still_dreaming_1 Depends. You'd need an __init__ for the from foo import test_foo. Unless you're changing to from foo.file import test_foo.
@still_dreaming_1 It's not unusual. Lots of packages use code in __init__.py to aggregate all the pieces of a package in one location (the package itself).
15:14
As far as fixing my import goes, can you please provide the exact line(s) of code you would use, in the style you would prefer if it were your own project, if you wanted to import a Cfg class from that cfg module? Maybe you already did, I'm just trying make sure I get the best possible example.
There are tonnes of mainstream examples of that which you could look at. Have you actually installed the package?
@still_dreaming_1 I don't understand the structure of your code. Is your path src/pybot/cfg/cfg.py removing parts to src/cfg.py?
@Peilonrayz I have tried both src/pybot/cfg.py and pybot/cfg.py (not having src/ dir), and I get the same result. I guess I would prefer to keep the src/ unless it complicates things too much.
This is a toy library I made from a discussion here. It is not very good. However, it's super-simple in its functionality and, thoughout development, I keep something like example.py outside of the package itself to test how it will work (or not) for users
@still_dreaming_1 from pybot.cfg import Cfg
15:23
@Peilonrayz I appreciate your patience. Now we are back to the very start of the conversation. That is a fully qualified name. Is it normal to use fully qualified names to import a module from the same package as the file containing said import?
Sorry I didn't notice you asking the question before. Yes normal. Relative imports are also normal.
It seems mypy understands if the import is absolute, but not if it is relative.
Relative ones would be like from .cfg import Cfg (assuming you're in pybot/foo.py)
@Peilonrayz That's it! So my line of code was from cfg import Cfg and it needed to be from .cfg import Cfg. I was just missing a . to indicate it is relative
I'm not aware of you having discussed this before. Are you sure this even works outside of mypy?
15:27
When I ran the code with python, it seemed to work
But I didn't test it very thoroughly
@still_dreaming_1 Happy we figured the problem out in the end :)
@Peilonrayz Thank you!!
That's a good way to conflate problems
In any case, glad it's fixed
@roganjosh well it's hard to test things thoroughly in a language you are just getting started with when you can't even figure out what is the right way to do imports yet. Anyway, I'm actually planning to build a testing framework that merges the concepts/act of testing and developing together into a single act. I'm not yet familiar with python, and have attempted building this in many different languages, and now am trying in python. I got a V1 working in php, and it was great. But I hate php
@still_dreaming_1 I'm not doubting that it's difficult; it doesn't change the feedback being true, though. I gave you the most minimal example I could give
FWIW I don't use mypy. But it would be worth checking to see if it works without it before you layer things on
Mypy and typing, in general, is bolted on to python
15:48
Ok, I guess it would have been helpful to know for sure python understood the imports or not. Now I'm curious if it did.
Certainly something to test :) And I just duck questions on import mechanics on complex packages because I still find surprising things. I'd do that before I looked to mypy outputs, especially with it being static analysis
#!/bin/bash
mkdir -p src/pybot
echo "class Cfg: pass" > src/pybot/cfg.py
printf "from cfg import Cfg; print(Cfg())\nif __debug__: reveal_type(Cfg())" > src/pybot/__main__.py
mypy src
pushd src; python -m pybot; popd
src/pybot/__main__.py:2: note: Revealed type is "cfg.Cfg"
Success: no issues found in 2 source files
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'cfg'
Bit odd on mypy's end tbh. But changing to from .cfg fixes the error.
@Peilonrayz if __debug__: should be TYPE_CHECKING = False\nif TYPE_CHECKING:. And changes mypy's output...
16:14
I just realized I should have released the php v1 version as open source even though I was abandoning it, and just marked it as public archive since it does work, and expresses my vision as working code. Would have been a good addition to a "resume" of sorts and something I could point people to when explaining this idea. I still could as I do have the code, but in my hatred of php I deleted php and all my tools off my computer haha.
"I still could" so you have that choice.
I guess I will. It's the closest I've ever come to turning all my programming experience (been programming for about 20 years) into a framework that makes programming better (my vision of "better" at least). It's inspired by the principle of environmental design from the book "Willpower Doesn't Work", where you design your environment to help you get the results you want, and motivated by my ADD brain that is very bothered by something taking slightly more effort than it needs to.
16:41
You have more coding experience than me. I guess I would just say that types were retrofitted to python, so there are always corner cases, and there are people (like me) that pay no attention to them
That's a bit harsh, I guess. If the type is specified, then it does help. But I never expect a type to be specified
Yeah that is why I avoided python for a while with this project, after abandoning php. But now I have my reasons for at least attempting it with python. The types and static analysis of them do seem better at least than in php, so maybe it will be good enough. If python ends up not being a good fit for me and this project, will prolly go back to Scala.
17:37
@still_dreaming_1 I also have ADD. Btw, didn't know that book but, it seems to me like the title and the content is contradictory (didn't read it entirely yet, but the synopsis and my own guessing seems to correlate I think). They mention something akin to self-improvement, which is in of itself related to willpower (since it require motivation/determination which is a by-product of willpower). It would be truer to title it "Using your willpower intelligently" or something related, but I digress...
17:58
@NordineLotfi I'd presume the book is a habits+ book. The best habits take no effort to adopt, for example replacing cigs with lollipops have caused some chronic smokers to give up smoking. The title seems on-point if my presumption holds.
@Peilonrayz yeah, pretty much. I guess one could make it a habit (unconscious) vs making a conscious effort (actively doing it with willpower) hmm
I mean, I would see it as using your will in both cases either way, since at the start, you have to force yourself to change your environment and get used to it until it become an habit, vs constantly doing it with willpower. The end result would then be that you used your willpower more intelligently, I think
I smoke 20 cigarettes a day currently. I also did when I stopped cold-turkey after 7 years, and held than for 18 months until a break-up. On day 4 (typically the worst for withdrawal) I was in a beer garden drinking and didn't need a cig. All of that was from a desire and "the Easy Way to Stop Smoking"
"Give up" is a banned phrase in that book, because it suggests that you're losing something positive btw. "Stop smoking" not "give up smoking"
18:26
@NordineLotfi Following from your axiom I'd agree with you. I would approach the idea differently. If someone asked me how to self-improve I wouldn't say things like willpower, eat, sleep, and breath because such activities are required to do anything as a living person. Unless the area truly needs to be called out; a skinny person may need to eat more.
18:44
yeah, I agree. I guess saying something along the line of "just have more will" or "use your will" probably does not help at all, since everyone does it on some level (consciously or not). At that point, it's "how" you use it, and "how much" you have of it that counts, although it's probably harder to quantify since it's a bit ambiguous/vague at that point
 
1 hour later…
19:47
@NordineLotfi Yeah, the title puts a lot of people off. Basically the book is promoting the idea of focusing a good amount of your willpower on designing your environment, because if you don't your environment will design you because of how powerful environment is. You want to create an environment that can pull you toward your goals rather than always having to be pushing a boulder uphill.
So here is something funny. Now that MyPy understands the imports, Python no longer does. Maybe I'm running it wrong? I'm running `python src\pybot\main.py` (on Windows). Then I get: `from .cfg import Cfg
ImportError: attempted relative import with no known parent package`.
 
1 hour later…
21:20
Ah, I'm supposed to run the module, not a specific script, via: python -m src.pybot.main

« first day (4866 days earlier)      last day (310 days later) »