-3

A lot of my Python scripts interface with my C# code and when I make changes to my C# code, it breaks a ton of my Python scripts. I am running Visual Studio for all of my code and was wondering if there is a way to catch this during compilation? It's annoying to push changes and then someone complains that the script has broken because I changed my type or method header. Right now, I do a check where I make sure the method exists within the code before executing in Python but it would be nice to take one step further and have it be checked before I even push the code. We log an error when the method doesn't exist/has changed but having it taken a step further would be the goal.

1
  • So you are introducing breaking changes to an (internal) interface and you are surprised by client code actually breaking? Maybe version your C# code and deliver to yourself as if it were a 3rd party lib. Create UnitTests that represent your API Contract. So if you make changes and they break, you know you have breaking changes and need to release a new version of the C# part. While your Python part still uses the old version, it won't break. Then you can upgrade the python to your new C# API version. Commented May 23, 2024 at 7:59

1 Answer 1

1

There is no way to do this out-of-the-box. But there is a way I used in my career:

  1. Make C# API library (DTO, interfaces), without dependencies.
  2. On pre-compilation stage, generate Python hooks for those interfaces. Should be pretty straight-forward using reflection.
  3. Make some Python unit-tests, mocking C# interfaces, this will ensure integrity.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.