question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

two imports with the same import-name are not distinguised

See original GitHub issue

Describe the bug I am not yet sure how to reproduce which state, as I have two different observation:

Example 1:

Generated code:

from ...apimachinery.pkg.apis.meta import v1
from ..core import v1

(from: https://github.com/FlorianLudwig/pdk8s/blob/e9b5903c4f8cf584fe60a4a84709a42f7e63b771/pdk8s/gen/io/k8s/api/networking/v1beta1.py#L12)

Example 2:

Generated code:

from ...apimachinery.pkg.apis.meta import v1
from ..core import v1 as v1_1

(from: https://github.com/FlorianLudwig/pdk8s/blob/e9b5903c4f8cf584fe60a4a84709a42f7e63b771/pdk8s/gen/io/k8s/api/extensions/v1beta1.py)

In this example, the second import is renamed to avoid the collision but the references are not. Resulting in code trying to access module members that are in v1_1 but refer to v1. (Example)

Expected behavior

The second example is a step in the right direction (or maybe import more of the package name, in this example meta.v1 instead of just v1). But the references must be updated.

Version:

  • datamodel-code-generator: git master

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
FlorianLudwigcommented, Jul 28, 2020

Hey @koxudaxi

thanks!

I tested against current master. Looks good!

(It looks like you didn’t publish to pypi though)

1reaction
FlorianLudwigcommented, Jul 28, 2020

This is strange. I had the following error with poetry:

Because pdk8s depends on datamodel-code-generator (0.5.17) which doesn't match any versions, version solving failed.

Not sure what I did wrong, but is working now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Name of Import in Java, or import two classes with the ...
You cannot import two classes with the same name and use both of them unqualified. Import one class and use the fully qualified...
Read more >
Can python distinguish two different functions defined ... - Quora
Can python distinguish two different functions defined with the same name but imported from different modules?
Read more >
Absolute vs Relative Imports in Python
A relative import specifies the resource to be imported relative to the current location—that is, the location where the import statement is. There...
Read more >
5. The import system — Python 3.11.1 documentation
When a module is first imported, Python searches for the module and if found, ... re-import the named module, the two module objects...
Read more >
Chapter 7. Packages and Modules - Oracle Help Center
If two single-type-import declarations in the same compilation unit attempt to import types with the same simple name, then a compile-time error occurs,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found