-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Python] SyntaxError: from __future__ imports must occur at the beginning of the file #4600
Comments
Hi @pjmagee
It is strange the order of imports is not consistent with other clients Out of curiosity, if you manually edit the code to move the future import line to the top, does it solve the error message ? |
Yes it does, I use Jetbrains PyCharm and it suggests to move it to the top, which I do. Then the executions runs fine. I am coming across other errors still in some other files and sometimes also files with this issue, to do with module import however, I am not confident to report it as a Kiota issue yet, as the OpenAPI Specs I am dealing with have issues themselves as well, and im trying to understand if its our definitions which are broken or we wrote them without fully understanding the spec, or if its a Kiota problem. |
Please feel free to use the OpenAPI Spec listed in the page to reproduce it. The OpenAPI specs are public |
Thanks for the additional information. I'm guessing this import should be special cased so it's always at the top, no matter what. Is this something you'd like to submit a pull request for? |
I'm not confident to be honest. Most of my experience is in C# and I can see the solution is C# but what I'm not confident in is Python itself (and the various versions of Python, CPython etc). I've been using Kiota to generate in various languages and attempt at consuming our product(s) in languages we know our customers most likely use in the industry/market they're in. I can see Kiota is using Optional[str] which is a Python pre 3.7 thing from a quick search. Unsure if this futures thing could break previous versions or newer versions. |
Just to say, this one is kind of breaking the entire Python SDK, since it means all generated code is invalid. So people using the Python SDK need to use the IDE or some tool to move ALL future imports. |
What are you generating using Kiota, clients or plugins?
API Client/SDK
In what context or format are you using Kiota?
Linux executable
Client Library/SDK Language
Python
Describe the bug
I am trying to generate clients from OpenAPI Spec. I made sure to use 1.14.0
docker run -v ${PWD}/examples:/app/output mcr.microsoft.com/openapi/kiota:1.14.0 generate
Examples of invalid Python
Expected behavior
For all the future imports to remain at the top. But, I am new too Python so maybe it's a python version thing, but I couldn't find any more information and it does seem a bit odd.
How to reproduce
I have been using Powershell to generate clients for various specs. But this is one which has the issue:
Generated for
https://developer.icis.com/portals/api/sites/icis-live-portal/liveportal/apis/lnganalyticsapi/download_spec
I was then looping through in Python and generating based on some configuration/customisation
Open API description file
Kiota Version
1.14.0
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
No response
Configuration
No response
Debug output
Click to expand log
PS C:\Projects\test> .\generate-code.ps1 info: Kiota.Builder.KiotaBuilder[0] Cleaning output directory /app/output/Python/lnganalytics dbug: Kiota.Builder.KiotaBuilder[0] kiota version 1.14.0 dbug: Kiota.Builder.KiotaBuilder[0] cache file /tmp/kiota/cache/generation/5A0BABF09B68A6E28F55D7E23347DD3239C41A4BE33096C5882D067794222D1B/download_spec not found, downloading from https://developer.icis.com/portals/api/sites/icis-live-portal/liveportal/apis/lnganalyticsapi/download_spec info: Kiota.Builder.KiotaBuilder[0] loaded description from remote source dbug: Kiota.Builder.KiotaBuilder[0] step 1 - reading the stream - took 00:00:02.2025130 warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/0/id - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/month - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/1/id - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/month - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/id - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1basinTightnessScenarios~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/month - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/originDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/originDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/originDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/destinationDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/destinationDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/destinationDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/originDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/originDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/originDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/destinationDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/destinationDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/destinationDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/originDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/originDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/originDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/destinationDetails/mass - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/destinationDetails/volume - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1cargoes~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/destinationDetails/energyContent - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/startDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/startDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/endDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/endDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/startDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/startDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/endDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/endDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/startDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/startDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/endDateEarliest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1charters~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/endDateLatest - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/publishDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/startDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/endDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/publishDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/startDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/endDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecasts~1{id}/get/responses/200/content/application~1vnd.api+json/example/data - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecastValues/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/0/attributes/date - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecastValues/get/responses/200/content/application~1vnd.api+json/examples/example/value/data/1/attributes/date - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1forecastValues~1{id}/get/responses/200/content/application~1vnd.api+json/example/data - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/costAtOrigin - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/bunkerPrice - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/absoluteProfit - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/costAtOrigin - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/bunkerPrice - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/absoluteProfit - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/created - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/costAtOrigin - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/bunkerPrice - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1netbacks~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/absoluteProfit - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/transactionOrder - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/price/high - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/startDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/endDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/transactionOrder - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/startDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/endDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/transactionOrder - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/price/high - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/startDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1transactions~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/endDate - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1vessels/get/responses/200/content/application~1vnd.api+json/example/data/0/attributes/capacity - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1vessels/get/responses/200/content/application~1vnd.api+json/example/data/1/attributes/capacity - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/paths/~1vessels~1{id}/get/responses/200/content/application~1vnd.api+json/example/data/attributes/capacity - Data and type mismatch found. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/originDetails/properties/mass - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/originDetails/properties/volume - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/originDetails/properties/energyContent - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/destinationDetails/properties/mass - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/destinationDetails/properties/volume - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/CargoModel/properties/attributes/properties/destinationDetails/properties/energyContent - The format integer is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/ForecastValueModel/properties/relationships/properties/forecast/properties/data/properties/id - The format string is not supported by Kiota for the type string and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/TransactionModel/properties/attributes/properties/transactionOrder - The format int is not supported by Kiota for the type number and the string type will be used. warn: Kiota.Builder.KiotaBuilder[0] OpenAPI warning: #/components/schemas/VesselModel/properties/attributes/properties/capacity - The format int is not supported by Kiota for the type number and the string type will be used. dbug: Kiota.Builder.KiotaBuilder[0] step 2 - parsing the document - took 00:00:00.1235163 dbug: Kiota.Builder.KiotaBuilder[0] step 3 - updating generation configuration from kiota extension - took 00:00:00.0000954 dbug: Kiota.Builder.KiotaBuilder[0] step 4 - filtering API paths with patterns - took 00:00:00.0025663 dbug: Kiota.Builder.KiotaBuilder[0] step 5 - checking whether the output should be updated - took 00:00:00.0147879 dbug: Kiota.Builder.KiotaBuilder[0] step 6 - create uri space - took 00:00:00.0020997 dbug: Kiota.Builder.KiotaBuilder[0] InitializeInheritanceIndex 00:00:00.0020691 dbug: Kiota.Builder.KiotaBuilder[0] CreateRequestBuilderClass 00:00:00 dbug: Kiota.Builder.KiotaBuilder[0] MapTypeDefinitions 00:00:00.0170261 dbug: Kiota.Builder.KiotaBuilder[0] TrimInheritedModels 00:00:00 dbug: Kiota.Builder.KiotaBuilder[0] CleanUpInternalState 00:00:00 dbug: Kiota.Builder.KiotaBuilder[0] step 7 - create source model - took 00:00:00.1007565 dbug: Kiota.Builder.KiotaBuilder[0] 99ms: Language refinement applied dbug: Kiota.Builder.KiotaBuilder[0] step 8 - refine by language - took 00:00:00.0997416 dbug: Kiota.Builder.KiotaBuilder[0] step 9 - writing files - took 00:00:00.9085176 dbug: Kiota.Builder.KiotaBuilder[0] cache file /tmp/kiota/cache/generation/5A0BABF09B68A6E28F55D7E23347DD3239C41A4BE33096C5882D067794222D1B/download_spec is up to date and clearCache is False, using it info: Kiota.Builder.KiotaBuilder[0] loaded description from remote source dbug: Kiota.Builder.KiotaBuilder[0] step 10 - writing lock file - took 00:00:00.0176999 Generation completed successfully dbug: Kiota.Builder.KiotaBuilder[0] Api manifest path: /app/apimanifest.jsonOther information
The text was updated successfully, but these errors were encountered: