Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class interop support for mapping Python uuid.UUID values to/from .NET System.Guid, so generated bindings and runtime conversions no longer require manual string conversion or PyObject handling.
Changes:
- Extend the source generator type system and parser to recognize
UUID/uuid.UUIDand reflect it asGuid. - Add runtime conversion + importer support (
PyObject.From(Guid)/As<Guid>andPyObjectImporters.Uuid). - Add unit + integration tests and generator snapshot coverage for UUID/Guid round-tripping.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Integration.Tests/python/test_uuid.py | Adds Python functions returning/accepting uuid.UUID for end-to-end integration coverage. |
| src/Integration.Tests/UuidTests.cs | Adds integration tests validating Guid ↔ UUID conversion and parsing from string. |
| src/CSnakes.Tests/TypeReflectionTests.cs | Verifies UUID and uuid.UUID resolve to Guid in reflection mapping. |
| src/CSnakes.Tests/PythonTypeDefinitionParserTests.cs | Verifies the parser accepts both UUID and uuid.UUID. |
| src/CSnakes.Tests/PythonStaticGeneratorTests/FormatClassFromMethods.test_uuid.approved.txt | Snapshot showing generated signatures and return conversion using the UUID importer. |
| src/CSnakes.SourceGeneration/ResultConversionCodeGenerator.cs | Adds UUID result conversion generator case targeting Guid + PyObjectImporters.Uuid. |
| src/CSnakes.SourceGeneration/Reflection/TypeReflection.cs | Maps UuidType to Guid in both conversion directions. |
| src/CSnakes.SourceGeneration/Parser/Types/PythonTypeSpec.cs | Introduces UuidType and PythonTypeSpec.Uuid. |
| src/CSnakes.SourceGeneration/Parser/PythonParser.TypeDef.cs | Recognizes UUID / uuid.UUID as UuidType. |
| src/CSnakes.Runtime/Python/PyObjectImporters.cs | Adds PyObjectImporters.Uuid importer for Guid. |
| src/CSnakes.Runtime/Python/PyObject.cs | Adds PyObject.From(Guid/Guid?), Guid case in From(object?), and As<Guid> support. |
| src/CSnakes.Runtime/PyObjectTypeConverter.Uuid.cs | Implements the actual Guid ↔ uuid.UUID conversion logic. |
| src/CSnakes.Runtime/PublicAPI/net8.0/PublicAPI.Unshipped.txt | Declares newly added public API members for net8.0. |
| src/CSnakes.Runtime/PublicAPI/net9.0/PublicAPI.Unshipped.txt | Declares newly added public API members for net9.0. |
| src/CSnakes.Runtime.Tests/Converter/GuidConverterTest.cs | Adds runtime converter tests for multiple Guid cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
@atifaziz or @tonybaloney y'all still around? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add native
Guid↔ Pythonuuid.UUIDsupportAdds first-class support for
System.Guidas a native interop type, mapping to and from Python'suuid.UUID. No manual string conversion orPyObjectunwrapping is needed.Usage
Python:
C#:
How it works
The conversion goes through Python's standard
uuidmodule (always available in the stdlib):PyObject.From(Guid)callsuuid.UUID(guid.ToString())via the C APIPyObjectImporters.Uuidcallsstr(uuid_obj)and parses the result withGuid.ParseBoth directions use the canonical
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxstring representation, which bothGuid.ToString()andstr(uuid.UUID(...))produce by default.Changes
Source generation (
CSnakes.SourceGeneration)Parser/Types/PythonTypeSpec.csUuidTyperecord andPythonTypeSpec.Uuidstatic instanceParser/PythonParser.TypeDef.csUUIDanduuid.UUIDasUuidTypeReflection/TypeReflection.csUuidTypemaps toGuidin bothToPythonandFromPythondirectionsResultConversionCodeGenerator.csUuidTypecase generating.BareImportAs<Guid, PyObjectImporters.Uuid>()Generated signature for a
uuid.UUIDreturn type:Runtime (
CSnakes.Runtime)PyObjectTypeConverter.Uuid.cs(new)ConvertFromGuid/ConvertToGuidconversion logicPython/PyObjectImporters.csUuidimporterPython/PyObject.csFrom(Guid),From(Guid?)overloads;Guidcase inFrom(object?)andAs<T>PublicAPI/net8.0/PublicAPI.Unshipped.txtPublicAPI/net9.0/PublicAPI.Unshipped.txtTests
CSnakes.Runtime.Tests/Converter/GuidConverterTest.cs(new)PyObject.From/As<Guid>and theUuidimporterCSnakes.Tests/PythonTypeDefinitionParserTests.csUUIDanduuid.UUIDCSnakes.Tests/TypeReflectionTests.csGuidCSnakes.Tests/PythonStaticGeneratorTests/FormatClassFromMethods.test_uuid.approved.txt(new)Integration.Tests/python/test_uuid.py(new)Integration.Tests/UuidTests.cs(new)